package bigdata.hourglass.common.utils

import java.util
import java.util.Properties

import com.alibaba.fastjson.JSONObject


/**
 * @author leo.jie (weixiao.me@aliyun.com)
 * @organization DataReal
 * @version 1.0
 * @website https://www.jlpyyf.com
 * @date 2019/12/8 7:33 下午
 * @since 1.0
 */
object ObjGenerator {
  /**
   * json生产器
   *
   * @param tuples 元组类型数据
   * @return json对象
   */
  def newJson(tuples: (String, Any)*): JSONObject = {
    tuples.foldLeft(new JSONObject()) {
      case (obj, (k, v)) => obj.put(k, v)
        obj
    }
  }

  /**
   * map生成器
   *
   * @param tuples 元组类型数据
   * @return map 数据
   */
  def newMap(tuples: (String, String)*): util.HashMap[String, String] = {
    tuples.foldLeft(new util.HashMap[String, String]()) {
      case (map, (k, v)) => map.put(k, v)
        map
    }
  }

  /**
   * properties数据生成器
   *
   * @param tuples 元组类型数据
   * @return properties数据
   */
  def newProperties(tuples: (String, String)*): Properties = {
    tuples.foldLeft(new Properties()) {
      case (props, (k, v)) => props.put(k, v)
        props
    }
  }

}
